﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.ComponentModel;
using System.Reflection;

namespace MemoBoss
{
    public partial class DifficultySelect : UserControl
    {
        Action returnMethod;
        Action SetBackgroundPicture;
        Action<DifficultyLevel> PlayGame;
        public DifficultySelect(Action callback, Action SetBGPicture, Action<DifficultyLevel> playGame)
        {
            PlayGame = playGame;
            SetBackgroundPicture = SetBGPicture;

            returnMethod = callback;
            InitializeComponent();

        }

        private void goBack()
        {

            Hide.Begin();
            returnMethod();
        }


        private void btnBack_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {

            goBack();
        }

        private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void Show_Completed(object sender, EventArgs e)
        {
            if (App.Difficulty_MemoBoss_Unlocked)
            {
                imgMemoBossStop.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                imgMemoBossStop.Visibility = System.Windows.Visibility.Visible;
            }
            if (App.Difficulty_Hard_Unlocked)
            {
                imgHardStop.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                imgHardStop.Visibility = System.Windows.Visibility.Visible;
            }
            SetBackgroundPicture();
        }

        public void ExitScreen()
        {
            this.Hide.Begin();
        }

        private void btn_MouseLeave(object sender, MouseEventArgs e)
        {
            Release.Stop();
            Release.Children.ToList().ForEach(a => Storyboard.SetTarget(a, (DependencyObject)sender));
            Release.Begin();
        }

        private void btn_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Push.Stop();
            Push.Children.ToList().ForEach(a => Storyboard.SetTarget(a, (DependencyObject)sender));
            Push.Begin();
        }

        private void LaunchGame(DifficultyLevel difficulty)
        {
            goBack();
            PlayGame(difficulty);
        }

        private void btn_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            //SoundFX.PlaySoundEffect(SFX.ButtonClick);
            switch (((Rectangle)sender).Name)
            {
                case "btnEasy":
                    LaunchGame(DifficultyLevel.Easy);
                    break;
                case "btnMedium":
                    LaunchGame(DifficultyLevel.Medium);
                    break;
                case "btnHard":
                    if (App.Difficulty_Hard_Unlocked)
                    {
                        LaunchGame(DifficultyLevel.Hard);
                    }
                    else
                    {
                        MessageBox.Show("You need to reach level 25 in Easy mode to unlock this mode. Sweat it!");
                        return;
                    }
                    break;
                case "btnMemoBoss":
                    if (App.Difficulty_MemoBoss_Unlocked)
                    {
                        LaunchGame(DifficultyLevel.MemoBoss);
                    }
                    else
                    {
                        MessageBox.Show("You need to reach level 25 in Medium mode to unlock this mode. Good luck with that! Wuaahahahaha!!!");
                        return;
                    }
                    break;
            }
        }

    }
}
